﻿Imports System.Configuration

Namespace ind.settings
    ''' <summary>
    ''' This module is used only to simplify the operations
    ''' </summary>
    ''' <remarks></remarks>
    <Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
    Public Module SettingsShortcut
        ''' <summary>
        ''' link shortcut to settings
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property SettingsLink() As onecryptSettings
            Get
                Return ind.settings.onecryptSettings.Default
            End Get
        End Property
    End Module

End Namespace




'This class allows you to handle specific events on the settings class:
' The SettingChanging event is raised before a setting's value is changed.
' The PropertyChanged event is raised after a setting's value is changed.
' The SettingsLoaded event is raised after the setting values are loaded.
' The SettingsSaving event is raised before the setting values are saved.

Namespace ind.settings


    Public NotInheritable Class onecryptSettings
        Inherits PortableSettingsProvider

        Overrides Function GetAppSettingsFilename() As String

            Return "onecrypt.settings"

        End Function

        Private Shared defaultInstance As onecryptSettings

#Region "My.Settings Auto-Save Functionality"

        Public Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs)
            ind.settings.SettingsLink.saveProperties()
        End Sub

#End Region

        Public Shared ReadOnly Property [Default]() As onecryptSettings
            Get
                If defaultInstance Is Nothing Then
                    defaultInstance = New onecryptSettings()
                    defaultInstance.LoadProperties()
                End If
                Return defaultInstance
            End Get
        End Property

        Public Sub saveProperties()

            Me.SetPropertyValues(Me.getPropertiesByReflection)
        End Sub

        Public Sub LoadProperties()
            Me.GetPropertyValues(Me.getPropertiesByReflection)
        End Sub

        Public Function getPropertiesByReflection() As Reflection.PropertyInfo()
            Dim myType As Type = Me.GetType
            ' Get the properties. 
            Dim myPropertyInfo As Reflection.PropertyInfo() = myType.GetProperties((Reflection.BindingFlags.Public Or Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance))
            Return myPropertyInfo
        End Function 'Main


        <Global.System.Configuration.UserScopedSettingAttribute(), _
         Global.System.Configuration.DefaultSettingValueAttribute("")> _
        Public Property storedpwd() As String = ""

        <Global.System.Configuration.UserScopedSettingAttribute(), _
         Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
         Global.System.Configuration.DefaultSettingValueAttribute("True")> _
        Public Property storepwdCheck() As Boolean = True

        <Global.System.Configuration.UserScopedSettingAttribute(), _
         Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
         Global.System.Configuration.DefaultSettingValueAttribute("True")> _
        Public Property chkNotDecryptWithoutExtension() As Boolean = True

        <Global.System.Configuration.UserScopedSettingAttribute(), _
         Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
         Global.System.Configuration.DefaultSettingValueAttribute("False")> _
        Public Property chkIntegrateInWindowsMenu() As Boolean = False

        <Global.System.Configuration.UserScopedSettingAttribute()> _
        Public Property chkSaveProjectsOnExit() As Boolean = False

        Dim ExplorerLastFolderVar As String = ""
        <Global.System.Configuration.UserScopedSettingAttribute(), _
         Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
         Global.System.Configuration.DefaultSettingValueAttribute("")> _
        Public Property ExplorerLastFolder() As String
            Get
                Return ExplorerLastFolderVar
            End Get
            Set(value As String)
                ExplorerLastFolderVar = value
            End Set
        End Property
        Dim chkOpenAfterDecryptVar As Boolean = True
        <Global.System.Configuration.UserScopedSettingAttribute(), _
         Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
         Global.System.Configuration.DefaultSettingValueAttribute("True")> _
        Public Property chkOpenAfterDecrypt() As Boolean
            Get
                Return chkOpenAfterDecryptVar
            End Get
            Set(value As Boolean)
                chkOpenAfterDecryptVar = value
            End Set
        End Property
        Dim chkStartWithWindowsVar As Boolean = False
        <Global.System.Configuration.UserScopedSettingAttribute()>
        Public Property chkStartWithWindows() As Boolean
            Get
                Return chkStartWithWindowsVar
            End Get
            Set(value As Boolean)
                chkStartWithWindowsVar = value
            End Set
        End Property

        Dim LanguageSelectedVar As String
        <Global.System.Configuration.UserScopedSettingAttribute(), _
         Global.System.Configuration.DefaultSettingValueAttribute("")> _
        Public Property LanguageSelected() As String
            Get

                If LanguageSelectedVar Is Nothing Or LanguageSelectedVar = "" Then
                    LanguageSelectedVar = Globalization.CultureInfo.CurrentUICulture.Name 'use this for user interface messages
                    'lang = Globalization.CultureInfo.CurrentCulture.Name 'use this for formatting, like dates and others. This is selected by user in windows control panel.
                End If
                Return LanguageSelectedVar
            End Get
            Set(value As String)
                LanguageSelectedVar = value
                My.Application.ChangeUICulture(value)
                ind.encrypter.AppEventsClass.LanguageChangedEventRaise()
            End Set
        End Property

        Dim chkAppFirstInitVar As Boolean = False
        <Global.System.Configuration.UserScopedSettingAttribute(), _
         Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
         Global.System.Configuration.DefaultSettingValueAttribute("False")> _
        Public Property chkAppFirstInit() As Boolean
            Get
                Return chkAppFirstInitVar
            End Get
            Set(value As Boolean)
              
                chkAppFirstInitVar = value
            End Set
        End Property
    End Class

End Namespace